import 'package:flutter/services.dart';
import 'package:flutter_module/beans/data_layer_bean.dart';
import 'package:flutter_module/beans/element_bean.dart';
import 'package:flutter_module/beans/project_bean.dart';
import 'package:flutter_module/system/log_util.dart';

import 'ni_data_method_id.dart';

class NIDataProjectDispatcher {
  static const _tag = 'NIDataProjectDispatcher';

  ///创建数据图层
  Future<bool> saveProject(MethodChannel _dataChannel, Project project) async {
    LogUtil.instance.printf("${project.toMap()}");
    return await _dataChannel.invokeMethod(
        NIDataProjectMethodId.kDataSaveDataProject, project.toMap());
  }

  ///获取项目列表
  Future<List<Project>> getDataProjectList(MethodChannel _dataChannel) async {
    List<Project> list = [];
    var res = await _dataChannel
        .invokeMethod(NIDataProjectMethodId.kDataGetDataProjectList);
    if (res is List) {
      for (var map in res) {
        if (map is Map) {
          list.add(Project.from(map));
        }
      }
    }
    return list;
  }
}
